-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test case and proposed fix for path component with trailing colon (and string) #708
Add test case and proposed fix for path component with trailing colon (and string) #708
Conversation
See grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
Codecov Report
@@ Coverage Diff @@
## master #708 +/- ##
==========================================
+ Coverage 56.43% 56.43% +<.01%
==========================================
Files 30 30
Lines 3046 3053 +7
==========================================
+ Hits 1719 1723 +4
- Misses 1158 1159 +1
- Partials 169 171 +2
Continue to review full report at Codecov.
|
I'll provide a little more color on why I think this is so. Here's the relevant section of http.proto:
This is the syntax of templates, not the paths templates are to match. It's actually a template that defines the syntax of the input paths it matches. If a template doesn't include a verb, then any trailing colon and string in an input path must be a part of the final segment. |
CLAs look good, thanks! |
31ab2fe
to
92019a6
Compare
…onent Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
92019a6
to
6d5b579
Compare
bump on this (and cc @johanbrandhorst since i've seen you chime in on recent PRs 😃) |
}, | ||
}, | ||
reqMethod: "GET", | ||
reqPath: "/foo/bar:123", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the verb in this case "123"? What does it mean to have a verb of 123?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the verb in this case "123"?
My reading of the HttpRule spec makes me interpret it like this: this path matches the path template in the stub pattern, which has no verb, so "123" isn't a verb (I try to make a case for this reading in #708 (comment)). Instead, "bar:123" is the captured value of the id
variable.
To flesh this out further:
- An HTTP rule path template describes a set of paths, basically by a regular expression
- If a request path is matched by an RPC's HTTP rule (regular expression), then it is handled by that RPC, with fields mapped according to the rule
- It follows that if an HTTP rule path template doesn't end with a verb, then it expects no verb, and the trailing path component will be scanned the same way as any other segment or variable
Here's another way to think about it: an alternative implementation of these patterns in grpc-gateway could have been to build up golang regexp.Regexp
s directly from the HTTP rules. Then when a request comes in, iterate through the regexps and use the last one that matches the path. Example mappings from rule to regular expression ([^/]*
probably isn't precisely correct, it's just an approximation of "The syntax *
matches a single path segment"):
get: "/foo/{id}" => "/foo/(?P<id>[^/]*)"
get: "/foo/{id}:myverb" => "/foo/(?P<id>[^/]*):myverb"
get: "/foo/{id}/bar" => "/foo/(?P<id>[^/]*)/bar"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achew22, does this make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. You are trying to describe the positive case, and not the negative case as I had interpreted it. That seems entirely reasonable. Merging.
Thanks so much for fighting through my confusion and for contributing to the project as a whole!
* Add explicit dependency versions (grpc-ecosystem#696) Version constraints are copied from existing Bazel rules. In the future, these version upgrades must be performed atomically. * Add OpenTracing support to docs (grpc-ecosystem#705) * protoc-gen-swagger: support all well-known wrapper types There were a few well-known wrapper types missing from the wkSchemas map. In specific UInt32Value, UInt64Value and BytesValue. This change handles them (and maps them to the same swagger types as the non-wrapped values) This also fixes the mapping of Int64Value. The Int64Value handling maps the value to a swagger integer. The documentation for Int64Value indicates that it should be mapped to a JSON string (also the mapping for normal int64 in protoc-gen-swagger maps it to a string, so this was inconsistent.) * Add test case and proposed fix for path component with trailing colon (and string) (grpc-ecosystem#708) * If a pattern has no verb, match with a verb arg appended to last component Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com> * Fix up examples * Make support paths option Make protoc-gen-grpc-gateway support paths option such like golang/protobuf#515.
Then, how to gain the old behavior of |
Who can tell me what's the meaning of syntax |
Actually it matches to the And in #224 , I don't think URN is valid inside URL, they are exclusive. |
Hi @kassiansun. It would be useful in these examples to not only have the path pattern but also some example paths and expected variable binding. For example: pattern: pattern: Does that make sense? |
No, the real behavior is |
#224 makes no sense, users should not use |
…lity" This reverts commit 60a328a.
… (and string) (grpc-ecosystem#708) * If a pattern has no verb, match with a verb arg appended to last component Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
The solution for grpc-ecosystem#224 turned out to break backwards compatibility, so we're going to have to find another solution for users who desire this behaviour. Also adds test cases from grpc-ecosystem#760.
If a pattern has no verb, match with the verb argument appended to last component.
As I understand the implementation, parsing out a "verb" from the input path is a convenience for matching. Whether the colon and string are actually a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component.
There is a backwards compatibility issue here: this can change the behavior of existing rule sets. For example:
Before this change, only the second rule matched a request for
/users/123:averb
. After this change, both rules match (correctly, by my understanding of https://github.com/googleapis/googleapis/blob/master/google/api/http.proto). Note that the spec describes a deterministic way of breaking the tie:// **NOTE:** All service configuration rules follow "last one wins" order.
grpc-ecosystem/grpc-gateway's implementation looks buggy on this score, since it accepts the first matching handler.Fixes #224